extends CharacterBody2D

var  move_speed : float = 100
@export var animtor : AnimatedSprite2D
var is_game_over : bool = false
@export var buller_scene : PackedScene

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
	if not is_game_over:
		velocity = Input.get_vector("left", "right", "up", "down" ) * move_speed

		if velocity == Vector2.ZERO:
			animtor.play("idle")
		else:
			animtor.play("run")
		
		move_and_slide()

func game_over() -> void:
	is_game_over = true
	animtor.play("game_over")
	await get_tree().create_timer(3).timeout
	
	get_tree().reload_current_scene()
	

func _on_file() -> void:
	if velocity != Vector2.ZERO or is_game_over:
		return

	var bullet_node = buller_scene.instantiate()
	bullet_node.position = position + Vector2(6, 6)
	get_tree().current_scene.add_child(bullet_node)
	
	
